﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.EntityClient;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;

namespace xraiding.Models
{
    public class XRaidingRepository
    {
        public static List<RoleInfo> GetRoles(int classId)
        {
            var dataSource = GetXRaidingConnection();
            var roles = new List<RoleInfo>();
            dataSource.Classes.Single(c => c.ClassId == classId).Roles.ToList().ForEach(c => roles.Add(new RoleInfo(){ RoleId = c.RoleId, Description = c.Description }));
            return roles;
        }

        public static List<ClassInfo> GetClasses()
        {
            var dataSource = GetXRaidingConnection();
            var classes = new List<ClassInfo>();
            dataSource.Classes.ToList().ForEach(c => classes.Add(new ClassInfo() { ClassId = c.ClassId, Name = c.Name }));
            return classes;
        }

        public static Guid GetUserId()
        {
            var membershipUser = Membership.GetUser();
            if (membershipUser != null)
            {
                Guid id = new Guid(membershipUser.ProviderUserKey.ToString());
                return id;
            }
            return Guid.Empty;
        }

        public static XRaidingEntities GetXRaidingConnection()
        {                        
            return new XRaidingEntities();
        }
    }
}